package com.wind.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;


import com.wind.dto.resp.CounselorServiceDetailsRespDto;
import com.wind.entity.ConsultingRequired;
import com.wind.entity.Counselor;
import com.wind.service.*;
import com.wind.vo.ResultData;
import com.wind.vo.ResultDataGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * Created by Administrator on 2021/5/21.
 */
@Api(tags = "咨询师")
@RestController
@RequestMapping("/counselor")
public class CounselorController {
    @Resource
    private ICounselorService counselorService;
    @Resource
    private IConsultingRequiredService consultingRequiredService;
    @Resource
    private ICounselorServiceDetailsRespDtoService counselorServiceDetailsRespDtoService;
    @Resource
    private IAppointmentTimeService appointmentTimeService;
    @ApiOperation("咨询师和规划师")
    @GetMapping("/list")
    public ResultData<List<Counselor>> list(){
        Wrapper wrapper = new EntityWrapper<Counselor>();
        wrapper.eq("is_active",1);
        wrapper.orderBy("recommend",false);
        wrapper.orderBy("advisory_count",false);
        List<Counselor> list = counselorService.selectList(wrapper);
        return  ResultDataGenerator.genSuccessResult(list,"查询成功");
    }
    @ApiOperation("咨询师主页")
    @GetMapping("/view/{id}")
    public ResultData<CounselorServiceDetailsRespDto> counselorHomepage(@PathVariable Integer id){
        //自定义的实体类
        CounselorServiceDetailsRespDto counselorServiceDetailsRespDto = counselorServiceDetailsRespDtoService.detailsQuery(id);
        if(Objects.isNull(counselorServiceDetailsRespDto)){
            return ResultDataGenerator.genFailResult(null,"没有咨询师和相关信息");
        }

        System.out.println("预约须知"+counselorServiceDetailsRespDto.getAppointmentNotices().size());
        System.out.println("预约时间"+counselorServiceDetailsRespDto.getAppointmentTimes().size());
        System.out.println("服务类型"+counselorServiceDetailsRespDto.getPaymentServes().size());
        System.out.println("评论"+counselorServiceDetailsRespDto.getComments().size());
        return ResultDataGenerator.genSuccessResult(counselorServiceDetailsRespDto,"查询成功");
    }
    @ApiOperation("咨询师详细信息")
    @GetMapping("/information/{id}")
    public ResultData<Counselor> counselorInformation(@PathVariable Integer id){
        Wrapper wrapper = new EntityWrapper<Counselor>();
        wrapper.eq("is_active",1);
        wrapper.eq("id",id);
        Counselor counselor = counselorService.selectOne(wrapper);
        if(Objects.isNull(counselor)){
            return ResultDataGenerator.genFailResult(null,"没有相关信息");
        }
        return ResultDataGenerator.genSuccessResult(counselor,"查询成功");
    }
    @ApiOperation("咨询必读")
    @GetMapping("/consultingRequired/{id}")
    public ResultData<ConsultingRequired> requiredLook(@PathVariable Integer id){
        Wrapper wrapper = new EntityWrapper<ConsultingRequired>();
        wrapper.eq("is_active",1);
        wrapper.eq("counselor_id",id);
        ConsultingRequired consultingRequired = consultingRequiredService.selectOne(wrapper);
        if(Objects.isNull(consultingRequired)){
            return ResultDataGenerator.genFailResult(null,"没有相关信息");
        }
        return ResultDataGenerator.genSuccessResult(consultingRequired,"查询成功");
    }

}
